import axios from "axios"
import {
    prefix
} from './config'
import {
    Message
} from 'element-ui'
export default {
    zhycget(url, dtat) {
        return new Promise((resolve) => {
            axios.get(prefix + url, {
                params: dtat,
                headers: {
                    'Authorization': localStorage.token
                }
            }).then(function (response) {
                if (response.data.code != 200) {
                    Message({
                        message: response.data.msg,
                        type: 'error',
                        duration: 5 * 1000
                    })
                    return
                }
                resolve(response.data)
            })
        })
    },
    zhycpost(url, dtat) {
        for (let key in dtat) {
            if (!dtat[key]) {
                delete dtat[key]
            }
        }
        return new Promise((resolve) => {
            axios({
                method: 'post',
                url: prefix + url,
                data: dtat,
                headers: {
                    'Authorization': localStorage.token
                }
            }).then((response) => {
                if (response.data.code != 200) {
                    Message({
                        message: response.data.msg,
                        type: 'error',
                        duration: 5 * 1000
                    })
                    return
                }
                resolve(response.data)
            });
        })
    }
}
